<cfparam default="" name="PageType" />

<cfset Providers = BASE.SCF_Exchange_GetEmployeesInDL("CN=SCF Elders Program,OU=Dynamic Groups,OU=SCFUsers,DC=SouthcentralFoundation,DC=com")/>
<cfset prov_list = "" />
<cfloop from="1" to="#ArrayLen(Providers)#" index="i" >
<cfset prov_list &= "#Providers[i].RosettaID#," />
</cfloop>

<cfoutput>

	<cfif PageType EQ "PDF" >
        
        <cfdocument format="pdf"> 
            
            <h2>Activce Client List</h2>
        
            <table style="font-size:10px" cellpadding="2">
                <thead>
                    <tr>
                        <th align="left" style="border-bottom:1px solid ##000">Last Name</th>
                        <th align="left" style="border-bottom:1px solid ##000">First Name</th>
                        <th align="left" style="border-bottom:1px solid ##000">DOB</th>
                        <th align="left" style="border-bottom:1px solid ##000">Phone</th>                        
                        <th align="left" style="border-bottom:1px solid ##000" width="25%">Address</th>
                        <th align="left" style="border-bottom:1px solid ##000">Priority</th>
                        <th align="left" style="border-bottom:1px solid ##000">Provider</th>
                        <th align="left" style="border-bottom:1px solid ##000">Emerg. Contact Name</th>  
                        <th align="left" style="border-bottom:1px solid ##000">Emerg. Phone</th>                 
                    </tr>
                </thead>
                
                <tbody>
                    <cfloop query="QUERIES.ActivceClientList" >
                        <tr>
                            <td>#LastName#</td>
                            <td>#FirstName#</td>
                            <td>#DateFormat(DOB, 'mm/dd/yyyy')#</td>
                            <cfif HomePhone NEQ "" or HomePhone NEQ 'NULL'>
                                <td>#HomePhone#</td>
                            <cfelse>
                                <td>#CellPhone#</td>
                            </cfif>
                            <cfif MailingAddress EQ "" or MailingAddress EQ 'NULL'>
                                <td>#Address# #AptSpaceNo# #City#, #State# #Zip#</td>
                            <cfelse>
                                <td>#MailingAddress# #MailingAptSpaceNo# #MailingCity#, #MailingState# #MailingZip#</td>
                            </cfif>
                            <td>#PriorityName#</td>
                            <cfif ListFind( prov_list, ProviderID) NEQ 0 >
                                <td>#BASE.SCF_EMPLOYEE_GetEmployee( ProviderID ).FullName#</td>
                            <cfelse>
                                <td>[Not Found]</td>
                            </cfif>
                            <td>#EmergencyContactName#</td>
                            <td>#EmergencyContactHomePhone#</td>
                        </tr>
                    </cfloop>
                </tbody>        
            </table>

        </cfdocument>
        
        
    <cfelseif PageType EQ "XLS">
    
        <!--- Set this HTTP Document as an Excel Spreadsheet --->
        <cfheader name="Content-Type:" value="application/vnd.ms-excel">
        <cfheader name="Content-Disposition:" value="attachment; filename=MailingList#DateFormat(now(), 'mm-dd-yyyy')#.xls">

        <!--- Output ONLY items enclosed in CF tags --->
        <cfsetting enablecfoutputonly="true">
        
            <table style="font-size:10px" cellpadding="2">
                <thead>
                    <tr>
                        <th align="left" style="border:1px solid ##000">Last Name</th>
                        <th align="left" style="border:1px solid ##000">First Name</th>
                        <th align="left" style="border:1px solid ##000">DOB</th>
                        <th align="left" style="border:1px solid ##000">Phone</th>
                        <th align="left" style="border:1px solid ##000" width="25%">Address</th>
                        <th align="left" style="border:1px solid ##000">Priority</th>
                        <th align="left" style="border:1px solid ##000">Provider</th>
                        <th align="left" style="border:1px solid ##000">Emerg. Contact Name</th>  
                        <th align="left" style="border:1px solid ##000">Emerg. Phone</th>                         
                    </tr>
                </thead>
                
                <tbody>
                    <cfloop query="QUERIES.ActivceClientList" >
                        <tr>
                            <td style="border:1px solid ##000">#LastName#</td>
                            <td style="border:1px solid ##000">#FirstName#</td>
                            <td style="border:1px solid ##000">#DateFormat(DOB, 'mm/dd/yyyy')#</td>
                            <cfif HomePhone NEQ "" or HomePhone NEQ 'NULL'>
                        		<td style="border:1px solid ##000">#HomePhone#</td>
							<cfelse>
                                <td style="border:1px solid ##000">#CellPhone#</td>
                            </cfif>
                            <cfif MailingAddress EQ "" or MailingAddress EQ 'NULL'>
                                <td style="border:1px solid ##000"> #Address# #AptSpaceNo# #City#, #State# #Zip#</td>
                            <cfelse>
                                <td style="border:1px solid ##000">#MailingAddress# #MailingAptSpaceNo# #MailingCity#, #MailingState# #MailingZip#</td>
                            </cfif>
                            <td style="border:1px solid ##000">#PriorityName#</td>
                            <cfif ListFind( prov_list, ProviderID) NEQ 0 >
                                <td style="border:1px solid ##000">#BASE.SCF_EMPLOYEE_GetEmployee( ProviderID ).FullName#</td>
                            <cfelse>
                                <td style="border:1px solid ##000">[Not Found]</td>
                            </cfif>
                            <td style="border:1px solid ##000">#EmergencyContactName#</td>
                            <td style="border:1px solid ##000">#EmergencyContactHomePhone#</td>
                        </tr>
                    </cfloop>
                </tbody>        
            </table>
        
         </cfsetting>
        
    <cfelse>  
     
     	<!---HTML header, css links, js links, and page title--->
    	#BASE.htmlHeader("", "", "Elder's Program - Reports")#
    	<!---HTML header, css links, js links, and page title--->
    
        <h2>Activce Client List  - #QUERIES.ActivceClientList.RecordCount# Elders</h2>
        
        <table>
            <thead>
                <tr>
                    <th align="left" style="border-bottom:1px solid ##000">Last Name</th>
                    <th align="left" style="border-bottom:1px solid ##000">First Name</th>
                    <th align="left" style="border-bottom:1px solid ##000">DOB</th>
                    <th align="left" style="border-bottom:1px solid ##000">Phone</th>
                    <th align="left" style="border-bottom:1px solid ##000" width="25%">Address</th>
                    <th align="left" style="border-bottom:1px solid ##000">Priority</th>
                    <th align="left" style="border-bottom:1px solid ##000">Provider</th>
                    <th align="left" style="border-bottom:1px solid ##000">Contact Name</th>  
                    <th align="left" style="border-bottom:1px solid ##000">Contact Phone</th>                        
                </tr>
            </thead>
            
            <tbody>
                <cfloop query="QUERIES.ActivceClientList" >
                    <tr>
                        <td><a href="intake.cfm?ElderID=#ElderListID#">#LastName#</a></td>
                        <td><a href="intake.cfm?ElderID=#ElderListID#">#FirstName#</a></td>
                        <td>#DateFormat(DOB, 'mm/dd/yyyy')#</td>
                        <cfif HomePhone NEQ "" or HomePhone NEQ 'NULL'>
                        	<td>#HomePhone#</td>
                        <cfelse>
                        	<td>#CellPhone#</td>
                        </cfif>
                        <cfif MailingAddress EQ "" or MailingAddress EQ 'NULL'>
                            <td>#Address# #AptSpaceNo# #City#, #State# #Zip#</td>
                        <cfelse>
                            <td>#MailingAddress# #MailingAptSpaceNo# #MailingCity#, #MailingState# #MailingZip#</td>
                        </cfif>
                        <td>#PriorityName#</td>
                        <cfif ListFind( prov_list, ProviderID) NEQ 0 >
                            <td>#BASE.SCF_EMPLOYEE_GetEmployee( ProviderID ).FullName#</td>
                        <cfelse>
                            <td>[Not Found]</td>
                        </cfif>
                        <td>#EmergencyContactName#</td>
                        <td>#EmergencyContactHomePhone#</td>
                    </tr>
                </cfloop>
            </tbody>
        
        </table>
        <!---HTML footer, closes html and body tags.  Any footer info goes here--->
    	#BASE.htmlFooter()#
    	<!---HTML footer, closes html and body tags.  Any footer info goes here--->
    </cfif>
        
    
</cfoutput>